package com.example.demotest.demotest.controller;

import com.example.demotest.demotest.vo.UserVo;
import com.example.demotest.demotest.vo.UserVoTest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Size;

/**
 * @author x_weidanlang
 * @version 1.0
 * @date 2022/2/9 9:40
 */
@RestController
@RequestMapping("/v1")
@Validated
public class ValidationController {

    @PostMapping("/validationTest1")
    public String validationTest1(@RequestBody @Valid UserVo UserVo){
        return "成功";
    }

    @GetMapping("/testValidation2")
    public String testValidation1(@Valid @RequestParam("name") @Size(max = 10,message = "最大为10,最小为5",min = 5) String name,
                                  @RequestParam("age") @Max(value = 100,message = "最大为100") int age){
        return name;
    }

    @PostMapping("/testValidation3")
    public String testValidation3(@RequestBody UserVoTest userVoTest){
        System.out.println("................."+userVoTest.getUserName());
        return userVoTest.getUserName();
    }


}
